<table class="altrowstable" id="categoryListDiv">
    <thead>
    <tr>
        <th>序号</th>
        <th>分类序号</th>
        <th>产品类别名称</th>
        <th>产品描述</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody id="tableBody"></tbody>
</table>

<div  style="position: absolute; margin-top: 0px;padding-left: 700px">

    <ul id="page">分页</ul>
</div>

<input type="button" value="添加" onclick="addCategory('updateCategory.html')" style="margin-left: 600px ; position: absolute; margin-top: 30px; font-size: 18px ; border: #84fab0; background-color: #84fab0">


<script id="categoryTemplate" type="text/html">{{each data}}
<tr>
    <td >{{$index+1}}</td>
    <td>{{$value.categoryID}}</td>
    <td>{{$value.name}}</td>
    <td>{{$value.remark}}</td>
    <td><span style="color: #b50f11" onclick="deleCategory(this)" id={{$value.categoryID}}   >删除&nbsp;&nbsp;</span><span style="color: #4a5fb5;" onclick="updateCategory('updateCategory.html','{{$value.categoryID}}')">修改</span></td>
</tr>
{{/each}}
</script>
<script>
function addCategory(url) {
   Ajax.getHtml(url,
   function (html) {
       Ajax.post("/addCategory",null,
       function (reslut) {
           $('#categoryID').val(reslut.data);
       });
       layer.open(
           {
               type:1,
               title:'产品类别添加',
               area: ['800px',['400px']],
               content: html,
               btn: ['确认', '取消'],
               yes:function () {
                   var categoryID = $('#categoryID').val();
                   var name = $('#categoryName').val();
                   var remark=$('#remark').val();
                   Ajax.post('/addCategory2',{
                       categoryID:categoryID,
                       name:name,
                       remark:remark
                   }, function (result) {
                       doResult(result, function () {
                           layer.closeAll()
                           show('category.html')
                           layer.alert(result.msg)
                       })
                   })
               }
           })
   })
}
    

    function updateCategory(url,Obj) {
        var categoryID1=Obj;
        Ajax.getHtml(url,
            function (html) {
            Ajax.post(
                "/updateCategory",
                {
                    categoryID:categoryID1
                },
                function (result) {
                    $('#categoryID').val(result.data.categoryID);
                    $('#categoryName').val(result.data.name);
                    $('#remark').val(result.data.remark);
                }
            );

            layer.open({
                type:1,
                title:'产品类别修改',
                area: ['800px',['400px']],
                content: html,
                btn: ['确认', '取消'],
                yes :function () {
                    var categoryID = $('#categoryID').val();
                    var name = $('#categoryName').val();
                    var remark=$('#remark').val();

                    Ajax.post("/updateCategory2",
                        {
                            categoryID:categoryID,
                            name:name,
                            remark:remark
                        },
                        function (result) {
                            doResult(result, function () {
                                layer.closeAll();
                                show('category.html');
                            })
                        }
                    )
                }
            })
        })
    }
    
    
    
    
    
    function deleCategory(Obj){
        var flat= window.confirm('确认删除?');
        if (flat==true) {
            var id = Obj.id;
            Ajax.post(
                "/deleteCategory",
                {
                    categoryID:id
                },
                function (result) {
                    doResult(result, function () {
                        show('category.html');
                    })
                }
            )
        }else {
            return false;
        }


    }

    $(function () {

        showPage({
            currentPage: 1,
            pageSize: 3,
            url: '/categoryList',
            templateId: 'categoryTemplate',
            contentId: 'tableBody',
        })
    })
</script>